package com.homewoek.thread;

/**
 * @Author:Ren2048
 * @Date:2021/9/1
 * @Description:com.homewoek.thread
 * @Version:1.8.0_261
 */
//1.使用两个线程分别输出100以内的奇数和偶数，并按从小到大的顺序输出。
public class NumsSort {
    class ThreadA implements Runnable{
        @Override
        public void run() {
            System.out.println("100以内奇数");
            int i = 0;
            while(i < 100){
                if (i % 2 != 0)
                    System.out.print(i + "\t");
                i++;
            }
            System.out.println();
        }
    }

    class ThreadB implements Runnable{
        @Override
        public void run() {
            System.out.println("100以内偶数");
            int i = 1;
            while(i < 100){
                if (i % 2 == 0)
                    System.out.print(i + "\t");
                i++;
            }
            System.out.println();
        }
    }

    public void startA(){
        Runnable rb = new ThreadA();
        Thread threada = new Thread(rb);
        threada.start();
    }

    public void startB(){
        Runnable rb = new ThreadB();
        Thread threadb = new Thread(rb);
        threadb.start();
    }

    public static void main(String[] args) {
        NumsSort numsSort = new NumsSort();
        numsSort.startA();
        numsSort.startB();
    }
}
